import { PureComponent } from "react"
import propTypes from "./cartProps"

export default function isLoginHOC(OriginComponent, name) {
  class Cpn extends PureComponent {
    constructor(props) {
      super(props)
    }

    render() {
      const { token, setToken } = this.props
      return token ? (
        <OriginComponent {...this.props} />
      ) : (
        <button onClick={setToken}>请登录{name}</button>
      )
    }
  }

  Cpn.propTypes = propTypes
  return Cpn
}
